package tech.wisefin.track;

import com.thedeanda.lorem.Lorem;
import com.thedeanda.lorem.LoremIpsum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import tech.wisefin.track.product.Product;
import tech.wisefin.track.product.ProductRepository;

@Slf4j
@SpringBootApplication
@EnableJpaAuditing
@EnableAsync
public class TrackApplication implements ApplicationRunner {

    private final ProductRepository repository;

    private final TrackConfiguration config;

    public TrackApplication(ProductRepository repository, TrackConfiguration config) {
        this.repository = repository;
        this.config = config;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("生成数据初始化产品数据");
        Lorem lorem = LoremIpsum.getInstance();

        for (int i = 0; i < 5; i++) {
            Product p = new Product();
            p.setName("保险产品 " + lorem.getLastName());
            p.setDescription(lorem.getParagraphs(1, 2));
            repository.save(p);
        }

    }

    public static void main(String[] args) {
        SpringApplication.run(TrackApplication.class, args);
    }
}
